package com.hong.strategy.register;

import com.hong.Config.ConfigManager;
import com.hong.RpcServer;
import com.hong.config.constant.ServerConfig;
import com.hong.listener.impl.Registrar;
import com.hong.qrpc.utils.StringUtils;
import com.hong.strategy.PropertiesStrategy;

import java.util.Map;

/**
 * @Author HQT
 * @Date 2022/7/23 11:25
 */
public class RegisterScanPackageStrategy implements PropertiesStrategy {

    @Override
    public void disposeProperties(RpcServer rpcServer) {
        ConfigManager configManager = rpcServer.getConfigManager();
        Map<Object, Object> profile = configManager.getProfile();
        String scanPackageUrls = (String) profile.get(ServerConfig.QRPC_REGISTER_SCANPACKAGE);
        if(!StringUtils.isEmpty(scanPackageUrls)){
            Registrar registrar = Registrar.addListener(rpcServer.getListenerManager());
            registrar.setScanPackageUrls(scanPackageUrls);
        }
    }
}
